#include "Component.h"


Component::Component(vector<Primitive*> p,vector<Material*> m, Texture *tex, Transformation* trans, bool mult )
{
	this->mats = m;
	this->tex = tex;
	this->trans=trans;
	
	multTex=mult;

	this->curMat=0;
	setPrimRef(p);
}

void Component::setCompRef( vector<Component*> c )
{
	this->cref=c;
}

void Component::setPrimRef( vector<Primitive*> p )
{
	this->pref=p;
}

void Component::act(float texLS, float texLT)
{

	float ls,lt;
	if(tex->inheritTex){
		ls=texLS; lt=texLT;
	}
	else {
		ls=tex->getLengthS();
		lt=tex->getLengthT();
	}

	glPushMatrix();

	
	trans->act();

	
	for(vector<Primitive*>::iterator it= pref.begin(); it != pref.end(); ++it){
		mats[curMat]->act();
		tex->act();
		(*it)->act(ls,lt);
	}
	

	for(vector<Component*>::iterator it= cref.begin(); it != cref.end(); ++it){
		mats[curMat]->act();
		tex->act();
		(*it)->act(ls,lt);
	}

	

	glPopMatrix();
}

Texture* Component::getTex()
{
	return tex;
}

void Component::nextMat()
{
	if(multTex)
		if(++curMat >= mats.size())
			curMat=0;
}
